<style lang='less' scoped>
    @import '~style/filter.less';
    .dataBox{
        margin-top: 20px;
        text-align: center;
    }
    .paginationBox{
        float: right;
        margin-top: 20px;
    }
</style>

<template>
    <div>
        <filter-box
            v-show='this.$route.name == "creditorList"'
            :issuerList='issuerList'
            :getButtonConfig='getButtonConfig'
            v-on:setFilterParams='setFormParams'
        ></filter-box>

        <table-box
            v-show='this.$route.name == "creditorList"'
            :data='tableData'
            :issuerList='issuerList'
            :totalSize='totalSize'
            :getButtonConfig='getButtonConfig'
            v-on:setTableParams='setFormParams'
        ></table-box>

    </div>
</template>

<script>
    import { mapGetters } from 'vuex'
    import filterBox from './filterBox.vue'
    import tableBox from './tableBox.vue'
    import importBox from './dialog/import.vue'
    import {postCreditorList} from 'api/creditor'
    import { getIssuerId} from 'api/common/index.js'

    export default {
        props:[],
        components:{
            filterBox,
            tableBox,
            importBox,
        },
        data(){
            return{
                issuerList:[],
                formQueryData:{
                    userId:sessionStorage.getItem('HKid'),
                },
                totalSize:0,
                tableData:null,
            }
        },
        computed:{
            getButtonConfig(){
                // console.log('index:  computed getButtonConfig', this.$store.getters.getButtonConfig('creditorList'))
                return this.$store.getters.getButtonConfig('creditorList')
            },
        },
        watch:{
        },
        methods:{
            async getIssuerId(params){
                try{
                    let back = await getIssuerId()
                    back = back.data;
                    console.log('getIssuerId',back)
                    if(back && back.resultCode ==='200'){
                        this.issuerList = back.result;
                    }else{
                        this.$message({
                            message: '发行方获取失败' + back.msg,
                            type: 'warning'
                        });
                    }
                }catch(err){
                    this.$message({
                            message: '发行方获取失败！',
                            type: 'warning'
                        });
                    console.error(err)
                }
            },
            setFormParams(e){
                console.log('setFormParams', e, this.formQueryData)
                this.formQueryData = Object.assign(this.formQueryData, e)
                this.postCreditorList(this.formQueryData)
            },
            async postCreditorList(params){
                try{
                    let back = await postCreditorList(params)
                    back = back.data;
                    console.log('postCreditorList',back)
                    if(back && back.resultCode =='200'){
                        this.tableData = back.result
                        this.totalSize =back.size
                    }else{
                        this.$alert(back.msg)
                    }
                }catch(err){
                    this.$alert('查询错误！')
                    console.error(err)
                }
            },
            setDialogVisible(e){
                let visivle = e ? true:false;
                console.log('setDialogVisible',visivle)
                return visivle

            },
            isPublishSucced(e){
                console.log('是否有发放卡卷',e)//发放了卡券要重载页面
                if(e){
                    this.getListData()
                }
            },
            goPage(name, parm={}, query={}){
                // console.log(name)
                this.$router.push({
                    name: name,
                    params:parm,
                    query:query,
                })
            },
            setTitleMsg(msg){
                this.$emit('setTitleMsg' , msg)
            }
        },
        created(){
            this.setTitleMsg(['债权匹配', '债权匹配'])
            this.getIssuerId()
        },
  }
</script>